import axios from "axios";
import nprogress from 'nprogress'
import store from "@/store";
// 引入进度条样式
import 'nprogress/nprogress.css'
const requests = axios.create({
  baseURL:'/api',
  timeout:6000
})
requests.interceptors.request.use((config)=>{
  // 游客身份验证
  if(store.state.detail.uuid_token){
    config.headers.userTempID = store.state.detail.uuid_token
  }
  // 判断token
  if(store.state.user.token){
    config.headers.token = store.state.user.token
  }
  nprogress.start()
  return config
})
requests.interceptors.response.use((res)=>{
    nprogress.done()
    return res.data
  },(err)=>{
    return Promise.reject(new Error(err || '失败了！'))
  }
)
export default requests